package com.ruoyi.web.controller.prt;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.prt.domain.PrtRechargePrice;
import com.ruoyi.prt.domain.vo.PrtRechargeLogVO;
import com.ruoyi.prt.service.IPrtRechargePriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 充值价格Controller
 *
 * @author xiaobo Yan
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/prt/price")
public class PrtRechargePriceController extends BaseController
{
    @Autowired
    private IPrtRechargePriceService prtRechargePriceService;

    /**
     * 查询充值价格列表
     */
    @PreAuthorize("@ss.hasPermi('system:price:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrtRechargePrice prtRechargePrice)
    {
        startPage();
        List<PrtRechargePrice> list = prtRechargePriceService.selectPrtRechargePriceList(prtRechargePrice);
        return getDataTable(list);
    }

    /**
     * 导出充值价格列表
     */
    @PreAuthorize("@ss.hasPermi('system:price:export')")
    @Log(title = "充值价格", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PrtRechargePrice prtRechargePrice)
    {
        List<PrtRechargePrice> list = prtRechargePriceService.selectPrtRechargePriceList(prtRechargePrice);
        ExcelUtil<PrtRechargePrice> util = new ExcelUtil<PrtRechargePrice>(PrtRechargePrice.class);
        return util.exportExcel(list, "price");
    }

    /**
     * 获取充值价格详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:price:query')")
    @GetMapping(value = "/{rechargePriceId}")
    public AjaxResult getInfo(@PathVariable("rechargePriceId") String rechargePriceId)
    {
        return AjaxResult.success(prtRechargePriceService.selectPrtRechargePriceById(rechargePriceId));
    }

    /**
     * 新增充值价格
     */
    @PreAuthorize("@ss.hasPermi('system:price:add')")
    @Log(title = "充值价格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrtRechargePrice prtRechargePrice)
    {
        return toAjax(prtRechargePriceService.insertPrtRechargePrice(prtRechargePrice));
    }

    /**
     * 修改充值价格
     */
    @PreAuthorize("@ss.hasPermi('system:price:edit')")
    @Log(title = "充值价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrtRechargePrice prtRechargePrice)
    {
        return toAjax(prtRechargePriceService.updatePrtRechargePrice(prtRechargePrice));
    }

    /**
     * 删除充值价格
     */
    @PreAuthorize("@ss.hasPermi('system:price:remove')")
    @Log(title = "充值价格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rechargePriceIds}")
    public AjaxResult remove(@PathVariable String[] rechargePriceIds)
    {
        return toAjax(prtRechargePriceService.deletePrtRechargePriceByIds(rechargePriceIds));
    }

    /**
     * 获取可选充值金额
     */
    @GetMapping("/getRechargePrice")
    @Log(title = "获取可选充值金额", businessType = BusinessType.SELECT)
    @PreAuthorize("@ss.hasRole('mobile')")
    public AjaxResult getRechargePrice()
    {
        return AjaxResult.success(prtRechargePriceService.selectPrtRechargePriceList(null));
    }
}
